function result = summary_stats(rets_cell , rets_string , latex_out , log_or_simple , file_name, hour_start,hour_end)

% This function creates a table of summary statistics computations for price returns

T = size(rets_cell{:,1},1);
N = size(rets_cell,2);

if log_or_simple == 1
    
    LHV = [];
    RHV = [];
    for k = 1 : N
        LHV = [LHV ; rets_cell{:,k}];
        temp = zeros(length(rets_cell{:,k}),N);
        temp(:,k) = 1;
        RHV = [RHV ; temp];
    end
    
    results_olsgmm = olsgmm(LHV,RHV,1,1);
    tstatsX(1,:) = results_olsgmm.tstat;


    tcdf_lower = tcdf(tstatsX,T-1);
    tcdf_upper = tcdf(tstatsX,T-1,'upper');
    
    pvaluesX = 2*min(tcdf_lower,tcdf_upper);
    
    alpha=0.05;
    
    pvalues_bonfc = fwer_bonf(pvaluesX,alpha)';

    
    
    obs = []; meanX = []; medianX = []; stdX = []; minX = []; maxX = []; skewX = []; kurtX = []; autocorrX = [];
        
    for k = 1 : N
        obs(1,k)        = length(rets_cell{:,k});
        meanX(1,k)      = 10000*nanmean(rets_cell{:,k});
        medianX(1,k)    = 10000*nanmedian(rets_cell{:,k});
        stdX(1,k)       = 10000*nanstd(rets_cell{:,k});
        minX(1,k)       = 10000*min(rets_cell{:,k});
        maxX(1,k)       = 10000*max(rets_cell{:,k});
        skewX(1,k)      = skewness(rets_cell{:,k});
        kurtX(1,k)      = kurtosis(rets_cell{:,k});
    end
            
    for k = 1 : N
        temp = autocorr(rets_cell{:,k},1);
        autocorrX(1,k) = temp(2);
    end
    
    % Now do binomial test
    pout = []; pos = [];  neg = [];
    p = 1/2;
    for k = 1 : N
        s = sign(rets_cell{:,k});
        pos(1,k) = sum(s(:)==1);
        neg(1,k) = sum(s(:)==-1);
        zer(1,k) = sum(s(:)==0);
        pout(1,k) = myBinomTest(pos(1,k),[pos(1,k)+neg(1,k)],p,'two');
    end
    
    out = [meanX;
        tstatsX;
        pvaluesX;
        pvalues_bonfc;
        medianX;
        stdX;
        skewX;
        kurtX];
    
    out = out(:,hour_start:hour_end);

    info.cnames = strvcat(rets_string);
    info.rnames = strvcat('Hour' , 'Mean' , 't-stat' , 'p-value' , 'BF p-value' , 'median' , 'Sdev' , 'Skew' , 'Kurt');
    info.fmt = '%6.2f';
    info.swidth = 220;
    info.hspc = 5;
    mprint1(out, info);
    if latex_out == 1
        info.fid = file_name;
        latextab2a(out, info)
    end
    
%     out = [meanX;
%         tstatsX;
%         100*(pos./(pos+neg+zer));
%         100*(neg./(pos+neg+zer));
%     pout];
%     
%     info.cnames = strvcat(rets_string);
%     info.rnames = strvcat('Hour' , 'Mean' , 't-stat' , '\% POS' , '\% NEG' , 'p-val');
%     info.fmt = '%6.2f';
%     info.swidth = 220;
%     info.hspc = 5;
%     mprint1(out, info);
%     if latex_out == 1
%         info.fid = file_name;
%         latextab2a(out, info)
%     end
    
elseif log_or_simple == 2 % BROKEN FROM HERE DOWN NEED TO UPDATE FROM ABOVE
    
    LHV = [];
    RHV = [];
    for k = 1 : N
        LHV = [LHV ; rets_cell{:,k}];
        temp = zeros(length(rets_cell{:,k}),N);
        temp(:,k) = 1;
        RHV = [RHV ; temp];
    end
    
    results_olsgmm = olsgmm(LHV,RHV,1,1);
    tstatsX(1,:) = results_olsgmm.tstat;
    
    tcdf_lower = tcdf(tstatsX,size(log_return_HbH,1));

    tcdf_upper = tcdf(tstatsX,size(log_return_HbH,1),'upper');
    
    pvaluesX = 2*min(tcdf_lower,tcdf_upper);
    
    alpha=0.05;
    
    
   
    for k = 1 : N
        obs(1,k) = length(rets_cell{:,k});
        meanX(1,k) = 10000*((nangeomean(1+rets_cell{:,k},1))-1);
        medianX(1,k) = 10000*nanmedian(rets_cell{:,k});
        stdX(1,k) = 10000*nanstd(log(1+rets_cell{:,k}));
        minX(1,k) = 10000*min(rets_cell{:,k});
        maxX(1,k) = 10000*max(rets_cell{:,k});
        skewX(1,k) = skewness(rets_cell{:,k});
        kurtX(1,k) = kurtosis(rets_cell{:,k});
    end
    
    for k = 1 : N
        temp = autocorr(rets_cell{:,k},1);
        autocorrX(1,k) = temp(2);
    end
    
    % Now do binomial test
    pout = []; pos = [];  neg = [];
    p = 1/2;
    for k = 1 : N
        s = sign(rets_cell{:,k});
        pos(1,k) = sum(s(:)==1);
        neg(1,k) = sum(s(:)==-1);
        zer(1,k) = sum(s(:)==0);
        pout(1,k) = myBinomTest(pos(1,k),[pos(1,k)+neg(1,k)],p,'two');
    end
    
    out = [meanX;
        tstatsX;
        pvaluesX;
        pvalues_bonfX;
        stdX;
        skewX;
        kurtX];
    
    out = out(:,hour_start:hour_end);

    info.cnames = strvcat(rets_string);
    info.rnames = strvcat('Hour' , 'Mean' , 't-stat' , 'p-value' , 'Bonf p-val' , 'Sdev' , 'Skew' , 'Kurt');
    info.fmt = '%6.2f';
    info.swidth = 220;
    info.hspc = 5;
    mprint1(out, info);
    if latex_out == 1
        info.fid = file_name;
        latextab2a(out, info)
    end
    
%     out = [meanX;
%         tstatsX;
%         100*(pos./(pos+neg+zer));
%         100*(neg./(pos+neg+zer));
%     pout];
%     
%     info.cnames = strvcat(rets_string);
%     info.rnames = strvcat('Hour' , 'Mean' , 't-stat' , '\% POS' , '\% NEG' , 'p-val');
%     info.fmt = '%6.2f';
%     info.swidth = 220;
%     info.hspc = 5;
%     mprint1(out, info);
%     if latex_out == 1
%         info.fid = file_name;
%         latextab2a(out, info)
%     end
    
end
result = [];